<?php

namespace app\common\model;

use Endroid\QrCode\QrCode;
use think\Db;
use think\Model;

class Order extends Model{


    // 表名
    protected $name = 'order';
    protected $pk = 'id';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';


    public function orderGoods()
    {
        return $this->hasMany('OrderGoods', 'order_id', 'id');
    }

    public function getPaytimeAttr($value, $data)
    {
        $value = $value ? $value : ($data['paytime'] ? $data['paytime'] : '');
        return $value ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getSendtimeAttr($value, $data)
    {
        $value = $value ? $value : ($data['sendtime'] ? $data['sendtime'] : '');
        return $value ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReceipttimeAttr($value, $data)
    {
        $value = $value ? $value : ($data['receipttime'] ? $data['receipttime'] : '');
        return $value ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCompletetimeAttr($value, $data)
    {
        $value = $value ? $value : ($data['completetime'] ? $data['completetime'] : '');
        return $value ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getCreateTimeAttr($value, $data)
    {
        $value = $value ? $value : ($data['createtime'] ? $data['createtime'] : '');
        return $value ? date("Y-m-d H:i:s", $value) : $value;
    }
}